package com.ruoyi.procurementmanagement.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.procurementmanagement.domain.EsSpecification;
import com.ruoyi.procurementmanagement.service.IEsSpecificationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 规格项Controller
 * 
 * @author ruoyi
 * @date 2025-06-16
 */
@RestController
@RequestMapping("/procurementmanagement/specification")
public class EsSpecificationController extends BaseController
{
    @Autowired
    private IEsSpecificationService esSpecificationService;

    /**
     * 查询规格项列表
     */
    @PreAuthorize("@ss.hasPermi('procurementmanagement:specification:list')")
    @GetMapping("/list")
    public TableDataInfo list(EsSpecification esSpecification)
    {
        startPage();
        List<EsSpecification> list = esSpecificationService.selectEsSpecificationList(esSpecification);
        return getDataTable(list);
    }

    /**
     * 导出规格项列表
     */
    @PreAuthorize("@ss.hasPermi('procurementmanagement:specification:export')")
    @Log(title = "规格项", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EsSpecification esSpecification)
    {
        List<EsSpecification> list = esSpecificationService.selectEsSpecificationList(esSpecification);
        ExcelUtil<EsSpecification> util = new ExcelUtil<EsSpecification>(EsSpecification.class);
        util.exportExcel(response, list, "规格项数据");
    }

    /**
     * 获取规格项详细信息
     */
    @PreAuthorize("@ss.hasPermi('procurementmanagement:specification:query')")
    @GetMapping(value = "/{specId}")
    public AjaxResult getInfo(@PathVariable("specId") Long specId)
    {
        return success(esSpecificationService.selectEsSpecificationBySpecId(specId));
    }

    /**
     * 新增规格项
     */
    @PreAuthorize("@ss.hasPermi('procurementmanagement:specification:add')")
    @Log(title = "规格项", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EsSpecification esSpecification)
    {
        return toAjax(esSpecificationService.insertEsSpecification(esSpecification));
    }

    /**
     * 修改规格项
     */
    @PreAuthorize("@ss.hasPermi('procurementmanagement:specification:edit')")
    @Log(title = "规格项", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EsSpecification esSpecification)
    {
        return toAjax(esSpecificationService.updateEsSpecification(esSpecification));
    }

    /**
     * 删除规格项
     */
    @PreAuthorize("@ss.hasPermi('procurementmanagement:specification:remove')")
    @Log(title = "规格项", businessType = BusinessType.DELETE)
	@DeleteMapping("/{specIds}")
    public AjaxResult remove(@PathVariable Long[] specIds)
    {
        return toAjax(esSpecificationService.deleteEsSpecificationBySpecIds(specIds));
    }
}
